﻿using WoodAdmin.Common.Helper.Net;
using WoodAdmin.Models;
using System;

namespace WoodAdmin.Common.Helper.Log
{
    /// <summary>
    /// 系统用户登录日志处理
    /// </summary>
    public class LoginLogHandler : LogHandler<LoginLog>
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public LoginLogHandler() : base(LogMode.LoginLog)
        {
            SysUser currentUser = null;
            var current = HttpContextHelper.Current;
            if (current != null)
            {
                currentUser = GlobalHelper.CurrentUser();
            }
            if (currentUser == null)
            {
                currentUser = new SysUser()
                {
                    NickName = "匿名用户"
                };
            }
            LogInfo = new LoginLog
            {
                CreateAccountId = currentUser?.ID.ToString(),
                ServerHost = HttpHelper.GetServerIp(),
                ClientHost = HttpHelper.GetClientIp(),
                UserAgent = HttpHelper.UserAgent(),
                OsVersion = HttpHelper.GetOsVersion(),
                LoginTime = DateTime.Now,
                IpAddressName = HttpHelper.GetAddressByApi()
            };

        }
    }
}
